package bossgo;

import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;

import java.io.*;
import java.util.Set;

public class CookieUtils {

    public static void saveCookies(WebDriver driver, String file) throws IOException {
        driver.get("https://www.zhipin.com");
        Set<Cookie> cookies = driver.manage().getCookies();
        try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))) {
            oos.writeObject(cookies);
        }
    }

    @SuppressWarnings("unchecked")
    public static Set<Cookie> loadCookies(String filePath) throws IOException, ClassNotFoundException {
        return loadCookies(new File(filePath));
    }

    @SuppressWarnings("unchecked")
    public static Set<Cookie> loadCookies(File file) throws IOException, ClassNotFoundException {
        try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
            return (Set<Cookie>) ois.readObject();
        }
    }
}


